﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;

namespace SUNRPA.CONTROLS.IMPL.controls {
    public class DeadLoopNAction:BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            DeadLoopNParam? param = item.ControlParam as DeadLoopNParam;
            string loopIndexName = param.LoopIndexName;
            this.GetStringVar(ref loopIndexName, globleData);
            long loopIndex = 0;
            while(true) { 
                this.saveVar(globleData, loopIndexName, new IntModel(loopIndexName, (int)loopIndex), DefaultContents.RUNNING_PARAM);
                //顺序执行定义在循环中的流程项
                for(int j = currentIndex + 1; j < item.EndTag.Index; j++) {
                    BaseControlActions.updateInfoDelegate(j);
                    j = ExecuteAction(flowItems[j], globleData, flowItems);
                    //执行每一个步骤更新一下信息
                }
                loopIndex++;
            }
            return item.EndTag.Index;
        }
    }
}
